﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Hired
{
    public partial class viewquestions : System.Web.UI.Page
    {
        private string category;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["category"] != null)
                {
                    category = (string)Request.QueryString["category"];
                }
                else
                {
                    category = "General";
                }
                ddlCategory.Text = category;
            }

            List<object> questionsList = DBQuestion.RetrieveLastAnsweredQuestionsByCategory(category);
            gvQuestions.DataSource = questionsList;
            gvQuestions.DataBind();
        }

        protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            Response.Redirect("viewquestions.aspx?category=" + Server.UrlEncode(ddlCategory.Text));
        }

        protected void lblAskQuestion_Click(object sender, EventArgs e)
        {
            Response.Redirect("askquestion.aspx?category=" + Server.UrlEncode(category));
        }

        protected string EvalLastAnswer(object LastAnswer)
        {
            if (LastAnswer != null)
            {
                return LastAnswer.ToString() + " by ";
            }
            else
            {
                return "-";
            }
        }

        protected string EvalLastPoster(object LastPoster)
        {
            if (LastPoster != null)
            {
                return LastPoster.ToString();
            }
            else
            {
                return "";
            }
        }
    }
}